import time

from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop026"
content = '这个有优惠吗?'
firefox = openBrowser(url)
#在首页的搜索框输入小米
firefox.find_element_by_xpath('//input[@name="keywords"]').send_keys('小米')
#点击搜索按钮
firefox.find_element_by_xpath('//input[@type="submit"]').click()
#点击小米电视
firefox.find_element_by_xpath('//img[@alt="小米（MI）电视4A标准版 L55M5-AZ/L55M5-AD 55英寸"]').click()
#切换到第二个页面
switchWindow(firefox,2)
#点击商品咨询
firefox.find_element_by_link_text('商品咨询').click()

#输入咨询内容
firefox.find_element_by_id('goods_ask_content').send_keys(content)
#点击提交咨询
firefox.find_element_by_xpath('//button[text()="提交咨询"]').click()
#登陆后台
firefox.get(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"商品管理",'商品咨询')
l="咨询数："
r="/)"
s=firefox.find_element_by_xpath('//body').text
num1 = int(reGetString(s,l,r))
DBshopLogin(firefox,'yuqilin','123456')
firefox.find_element_by_xpath('//td[contains(.,"小米（MI）电视4A标准版 L55M5-AZ/L55M5-AD 55英寸")]/following-sibling::td[6]/a[2]').click()
firefox.switch_to.alert.accept()
time.sleep(5)

num2 = reGetString(s,l,r)

try:
    num1==num2+1
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("% 测试失败"%testCase)
    getPhoto(firefox)

firefox.quit()
